<template>
  <base-card>
    <!-- 标题 -->
    <div class="top-outer-layer">
      <div class="border-left"></div>
      <div class="add-text">医生详情</div>
    </div>
    <div class="doc-info">医生信息</div>
    <el-descriptions :column="4">
      <el-descriptions-item label="医生编号">{{ detailsDoctorData._id }}</el-descriptions-item>
      <el-descriptions-item label="医生姓名">{{ detailsDoctorData.name }}</el-descriptions-item>
      <el-descriptions-item label="医生头像" align="center" :rowspan="1">
        <el-avatar :size="20" :src="detailsDoctorData.avatar" />
      </el-descriptions-item>
      <el-descriptions-item label="联系电话">{{ detailsDoctorData.phone }}</el-descriptions-item>
    </el-descriptions>
    <el-descriptions :column="1">
      <el-descriptions-item label="性别">{{ detailsDoctorData.gender == 0 ? '女' : '男' }}</el-descriptions-item>
      <el-descriptions-item label="医生简介">{{ detailsDoctorData.intro }}</el-descriptions-item>
      <el-descriptions-item label="医生擅长">{{ detailsDoctorData.intro }}</el-descriptions-item>
      <el-descriptions-item label="加入团队">{{detailsDoctorData.teamIds?.map(item => item.name).join('')
      }}</el-descriptions-item>
      <el-descriptions-item label="签约人数">{{detailsDoctorData.teamIds?.map(item => item.signNumber
      ).join('')}}</el-descriptions-item>
      <el-descriptions-item label="医生评分">{{ detailsDoctorData._id }}</el-descriptions-item>
      <el-descriptions-item label="创建时间">{{ detailsDoctorData.roleId?.createTime }}</el-descriptions-item>
      <el-descriptions-item label="创建人">{{ detailsDoctorData._id }}</el-descriptions-item>
      <el-descriptions-item label="账号状态">
        <el-switch class="mb-2" :active-value="1" :inactive-value="0" active-text="启用" inactive-text="禁用"
          inline-prompt />
      </el-descriptions-item>
    </el-descriptions>
    <el-button type="primary">发送消息</el-button>
    <el-button type="primary" @click="toUpdate(detailsDoctorData._id)">编辑医生信息</el-button>
    <el-button type="danger" @click="onDelete(detailsDoctorData._id)">删除</el-button>
    <el-button @click="onBack">返回</el-button>

  </base-card>

</template>

<script setup>
import { onMounted, ref } from 'vue';
import BaseCard from '../../components/base-card/BaseCard.vue';
import { detailDoctorsApi, removeDoctorsApi } from '../../api/doctors';
import { useRoute } from 'vue-router';
import { useRouter } from 'vue-router';
import { useFindData } from '../../composables/findData';
const router = useRouter()
const route = useRoute()
const { findDoctorDataAsync } = useFindData()
// 路径传参
console.log(route.params._id);
// 医生详情的数据
const detailsDoctorData = ref({})
onMounted(() => {
  getData()
})
const toUpdate = (_id) => {
  router.push(`/data/doctor/update/${_id}`)
}
// 获取一个医生的详情信息
const getData = () => {
  detailDoctorsApi({
    _id: route.params._id
  }).then(res => {
    detailsDoctorData.value = res.data
    console.log(detailsDoctorData.value);
  })
}
// 删除的请求
const ondelete = (_id) => {
  removeDoctorsApi(_id).then(res => {
    if (res.code == 200) {
      ElMessage({
        type: 'success',
        message: '删除成功',
      })
      findDoctorDataAsync()
    }
  })
}
// 删除的弹窗
const onDelete = (_id) => {
  ElMessageBox.confirm(
    '确定要删除医生信息吗？',
    '提示',
    {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning',
    }
  ).then(() => {
    ondelete({ _id })
    findDoctorDataAsync()
  }).catch(() => {
  })
}
const onBack = () => {
  router.back()
}
</script>

<style scoped>
.top-outer-layer {
  display: flex;
  height: 45px;
  border-bottom: 1px solid #dcdbdb;
  margin-bottom: 20px;
}

.border-left {
  width: 6px;
  height: 24px;
  background-color: rgba(41, 132, 248, 1);
  border-radius: 10px;
}

.add-text {
  margin-left: 10px;
  font-size: 18px;
  color: rgba(51, 51, 51, 0.898039215686275);
}

.doc-info {
  font-size: 16px;
  color: #333333;
  margin-top: 10px;
  margin-bottom: 30px;
}

.el-descriptions__label:not(.is-bordered-label) {
  margin-bottom: 20px;
}
</style>